<template>
  <div style="margin-top: 50px">
    <el-form :model="value" :rules="rules" ref="HomePopForm" label-width="120px" style="width: 600px" size="small">
      <el-form-item label="弹窗标题：" prop="productCategoryId">
       <el-input v-model="value.title"></el-input>
      </el-form-item>
      <p class="titletip">tips：标题不会在小程序展示，仅供后台数据展示</p>
      <!-- <el-form-item label="首页弹窗展示图片：" >
        <el-card shadow="never" class="cardBg">
          <div v-for="(item,index) in selectProductAttrPics" :key="index">
            <span>{{item.name}}:</span>
            <single-upload v-model="item.pic" style="width: 300px;display: inline-block;margin-left: 10px"></single-upload>
          </div>
        </el-card>
      </el-form-item> -->
      <el-form-item label="首页弹窗展示图片：">
        <single-upload v-model="value.showPic" tip='请上传 600*700px 的图片'></single-upload>
      </el-form-item>
      <!-- <el-form-item label="图片跳转地址：" prop="productCategoryId">
       <el-input v-model="value.frameUrl"></el-input>
      </el-form-item> -->
      <el-form-item label="开始时间：">
          <el-date-picker
            v-model="value.startTime"
            type="datetime"
            :picker-options="pickerOptions1"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间：">
          <el-date-picker
            v-model="value.endTime"
            type="datetime"
            :picker-options="pickerOptions1"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="选择仓库" required >
          <el-select v-model="value.depotId" placeholder="请选择">
            <el-option
              v-for="item in depotList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="弹出时间设置" required>
          <el-radio-group v-model="value.ruleType">
            <el-radio :label="1">只弹出1次</el-radio>
            <el-radio :label="2">每天弹出1次</el-radio>
            <el-radio :label="3">打开就弹出</el-radio>
          </el-radio-group>
        </el-form-item>
      <el-form-item style="text-align: center">
        <!-- <el-button type="primary" size="medium" @click="handleNext('HomePopForm')">下一步，填写商品促销</el-button> -->
       <el-button type="primary" size="medium" @click="handleFinishCommit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  // import {fetchListWithChildren} from '@/api/productCate'
  // import {fetchList as fetchBrandList} from '@/api/brand'
  //import {fetchList as fetchDeptList} from '@/api/depository'
  // import {getProduct} from '@/api/product';
  import SingleUpload from '@/components/Upload/singleUpload'
  // import {fetchList as fetchDepotList} from '@/api/depository'

  export default {
    name: "ProductInfoDetail",
    components:{SingleUpload},
    props: {
      value: Object,
      isEdit: {
        type: Boolean,
        default: false
      }
    },
    
    data() {
      return {
           //日期选择器配置
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },
        rules:{

        },
        depotList:[],//仓库列表
      };
    },
    created() {
     // this.getDepotList();
    //   this.getProductCateList();
    //   this.getBrandList();
      // this.getDepotList();
    },
    // computed:{
    //   //商品的编号
    //   productId(){
    //     return this.value.id;
    //   },
      
    // },
    watch: {
    //   productId:function(newValue){
    //     if(!this.isEdit)return;
    //     if(this.hasEditCreated)return;
    //     if(newValue===undefined||newValue==null||newValue===0)return;
    //     this.handleEditCreated();
    //   },
    //   selectProductCateValue: function (newValue) {
    //     console.log(newValue);
    //     if (newValue != null && newValue.length === 2) {
    //       this.value.productCategoryId = newValue[1];
    //       this.value.productCategoryName= this.getCateNameById(this.value.productCategoryId);
    //     } else {
    //       this.value.productCategoryId = null;
    //       this.value.productCategoryName=null;
    //     }
    //   }
    },
    methods: {
       getDepotList(){
        let self = this;
        fetchDeptList().then(({code,data})=>{
          if(code ==200 && data){
            self.depotList = data;
            // for(const item of data){
            //   if(item.isDefault){
            //     self.activeDept= item.name;//页面一进来，首先选择显示默认仓库
            //     self.listQuery.depotId = item.id;
            //     break;
            //   }
            // };
          }
        })
      },
         handleFinishCommit(){
             console.log("111")
            this.$emit('finishHomePop',this.isEdit);
            console.log("提交数据")
        }
    //   //处理编辑逻辑
    //   handleEditCreated(){
    //     if(this.value.productCategoryId!=null){
    //       this.selectProductCateValue.push(this.value.cateParentId);
    //       this.selectProductCateValue.push(this.value.productCategoryId);
    //     }
    //     this.hasEditCreated=true;
    //   },
    //   getProductCateList() {
    //     fetchListWithChildren().then(response => {
    //       let list = response.data;
    //       this.productCateOptions = [];
    //       for (let i = 0; i < list.length; i++) {
    //         let children = [];
    //         if (list[i].children != null && list[i].children.length > 0) {
    //           for (let j = 0; j < list[i].children.length; j++) {
    //             children.push({label: list[i].children[j].name, value: list[i].children[j].id});
    //           }
    //         }
    //         this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children});
    //       }
    //     });
    //   },
    //   getBrandList() {
    //     fetchBrandList({pageNum: 1, pageSize: 100}).then(response => {
    //       this.brandOptions = [];
    //       let brandList = response.data.list;
    //       for (let i = 0; i < brandList.length; i++) {
    //         this.brandOptions.push({label: brandList[i].name, value: brandList[i].id});
    //       }
    //     });
    //   },
    //   // getDepotList(){
    //   //   let self = this;
    //   //   fetchDepotList().then(res=>{
    //   //     if(res.code ==200){
    //   //       self.depotList = res.data;
    //   //     }
    //   //   })
    //   // },
    //   getCateNameById(id){
    //     let name=null;
    //     for(let i=0;i<this.productCateOptions.length;i++){
    //       for(let j=0;j<this.productCateOptions[i].children.length;j++){
    //         if(this.productCateOptions[i].children[j].value===id){
    //           name=this.productCateOptions[i].children[j].label;
    //           return name;
    //         }
    //       }
    //     }
    //     return name;
    //   },
    //   handleNext(formName){
    //     this.$refs[formName].validate((valid) => {
    //       if (valid) {
    //         this.$emit('nextStep');
    //       } else {
    //         this.$message({
    //           message: '验证失败',
    //           type: 'error',
    //           duration:1000
    //         });
    //         return false;
    //       }
    //     });
    //   },
    //   handleBrandChange(val) {
    //     let brandName = '';
    //     for (let i = 0; i < this.brandOptions.length; i++) {
    //       if (this.brandOptions[i].value === val) {
    //         brandName = this.brandOptions[i].label;
    //         break;
    //       }
    //     }
    //     this.value.brandName = brandName;
    //   }
    }
  }
</script>

<style scoped>
.titletip{
  font-size: 12px;
  color: red;
  margin-left: 60px;
}
</style>
